
#pragma once

#include <d3d9.h>
#include <d3dx9.h>
#include <autounk.h>
#include "sglrender.h"

class D3DRender : public SglRender
{

public:

	D3DRender();
	virtual ~D3DRender();

	HRESULT GetResult(VOID) const;

	virtual BOOL Create(HWND hWnd, INT nWidth, INT nHeight, BOOL bFullScreen);
	virtual BOOL BeginDraw();
	virtual BOOL Draw(PBUFFER pBuffer, COLORREF dwBgColor);
	virtual BOOL EndDraw();
	virtual BOOL DrawPixel(INT nX, INT nY, COLORREF dwColor, BYTE byAlpha);
	virtual BOOL Render(LPCRECT pRect);
	virtual VOID Destroy(VOID);

private:

	struct VERTEX
	{
		D3DXVECTOR4	sPosition;
		FLOAT		u;
		FLOAT		v;
	};

	HWND					m_Wnd;
	HRESULT					m_Result;
	SIZE					m_Size;
	LPDIRECT3DDEVICE9		m_D3DDevice;
	LPDIRECT3DSWAPCHAIN9	m_D3DSwapChain;
	LPDIRECT3DVERTEXBUFFER9	m_D3DVertexBuffer;

	BOOL CheckCapability(LPDIRECT3D9 pD3D);
	BOOL CleanUp(VOID);
	BOOL ClearDraw(VOID);
	BOOL CreateBackBuffer(UINT nWidth, UINT nHeight, LPDIRECT3DSWAPCHAIN9 &pD3DSwapChain);
	BOOL CreateTexture(PBUFFER pBuffer, LPDIRECT3DTEXTURE9 pD3DT);
	BOOL CreateBlock(PBLOCK pBlock, LPDIRECT3DTEXTURE9 &pD3DT);
	BOOL CopyTexture(LPDIRECT3DTEXTURE9 pD3DTDest, LPDIRECT3DTEXTURE9 pD3DTSrc, LPCRECT pRect);
	BOOL SetVertexBuffer(UINT nWidth, UINT nHeight, LPDIRECT3DTEXTURE9 pD3DT);
	BOOL ClearBackground(UINT nWidth, UINT nHeight, COLORREF dwBgColor);
	BOOL WriteTexture(D3DLOCKED_RECT *pLockRect, PBLOCK pBlock, INT nFormat);
	BOOL DrawScene(LPDIRECT3DTEXTURE9 pD3DT);
	BOOL DrawTexture(LPDIRECT3DTEXTURE9 pD3DT);

};
